package main

import (
	"crypto/md5"
	"crypto/rand"
	"encoding/base64"
	"encoding/hex"
	"fmt"
	"github.com/satori/go.uuid"
	"io"
)

func createUuid(){
	u1,err := uuid.NewV4()
	if err != nil{
		fmt.Printf("err 生成失败:%s\n",u1)
		return
	}
	fmt.Println(u1.String())

	u2, err := uuid.FromString("f5394eef-e576-4709-9e4b-a7c231bd34a4")
	if err != nil {
		fmt.Printf("Something gone wrong: %s\n", err)
		return
	}
	fmt.Printf("Successfully parsed: %s\n", u2)
}

func getMD5String(s string)string{
	h := md5.New()
	io.WriteString(h,s)
	return  hex.EncodeToString(h.Sum(nil))
}

func uniqueId() string{
	b := make([]byte,48)
	if _,err := io.ReadFull(rand.Reader,b);err != nil{
		return ""
	}
	return getMD5String(base64.URLEncoding.EncodeToString(b))
}

func main(){
	createUuid()
	fmt.Println(uniqueId())
}
